<html>
<head><meta charset="utf-8"><title>Layout::array · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html">Layout::array</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214325448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214325448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214325448">(Oct 23 2020 at 15:09)</a>:</h4>
<p>When compiling rustc <code>Layout::array</code> is the method with the 7th most llvm-ir of all functions</p>



<a name="214325563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214325563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214325563">(Oct 23 2020 at 15:10)</a>:</h4>
<p>are there some edge cases I am missing here, because I would expect this to pretty much be <code>Layout { size: size_of::&lt;T&gt;() * repeat, align: align_of::&lt;T&gt;() }</code></p>



<a name="214325713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214325713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214325713">(Oct 23 2020 at 15:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/122651-general/topic/Layout.3A.3Aarray/near/214325448">said</a>:</p>
<blockquote>
<p>When compiling rustc <code>Layout::array</code> is the method with the 7th most llvm-ir of all functions</p>
</blockquote>
<p>is that counting each separate monomorphization? or just a single monomorphization?</p>



<a name="214325826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214325826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214325826">(Oct 23 2020 at 15:11)</a>:</h4>
<p>maybe it could use the trick where it makes the generic parts separate from the rest?</p>



<a name="214325835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214325835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214325835">(Oct 23 2020 at 15:11)</a>:</h4>
<div class="codehilite"><pre><span></span><code>  Lines            Copies         Function name
  -----            ------         -------------
  21900013 (100%)  616680 (100%)  (TOTAL)
    455520 (2.1%)     412 (0.1%)  rustc_query_system::query::plumbing::get_query_impl::{{closure}}
    437054 (2.0%)    7609 (1.2%)  core::option::Option&lt;T&gt;::map
    376446 (1.7%)    3198 (0.5%)  &lt;alloc::vec::Vec&lt;T&gt; as alloc::vec::SpecExtend&lt;T,I&gt;&gt;::spec_extend
    354367 (1.6%)   35218 (5.7%)  core::ptr::drop_in_place
    274634 (1.3%)    3568 (0.6%)  core::iter::traits::iterator::Iterator::fold
    261490 (1.2%)    3198 (0.5%)  alloc::vec::Vec&lt;T&gt;::extend_desugared
    261488 (1.2%)    2216 (0.4%)  core::alloc::layout::Layout::array
    229826 (1.0%)     782 (0.1%)  hashbrown::raw::RawTable&lt;T&gt;::rehash_in_place
    214136 (1.0%)    1508 (0.2%)  alloc::raw_vec::RawVec&lt;T,A&gt;::grow_amortized
    203048 (0.9%)    2829 (0.5%)  &lt;alloc::vec::Vec&lt;T&gt; as alloc::vec::SpecFromIterNested&lt;T,I&gt;&gt;::from_iter
    172904 (0.8%)    2881 (0.5%)  std::thread::local::LocalKey&lt;T&gt;::try_with
</code></pre></div>



<a name="214325949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214325949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214325949">(Oct 23 2020 at 15:12)</a>:</h4>
<p><a href="https://doc.rust-lang.org/src/core/alloc/layout.rs.html#387-391">https://doc.rust-lang.org/src/core/alloc/layout.rs.html#387-391</a></p>



<a name="214326035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326035">(Oct 23 2020 at 15:12)</a>:</h4>
<p>maybe LLVM is inlining <code>pad_to_align</code>?</p>



<a name="214326054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326054">(Oct 23 2020 at 15:12)</a>:</h4>
<p>oh yeah who put <code>#[inline]</code> on that <span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span></p>



<a name="214326081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326081">(Oct 23 2020 at 15:13)</a>:</h4>
<p>try removing that and see if it helps?</p>



<a name="214326116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326116">(Oct 23 2020 at 15:13)</a>:</h4>
<p>especially since it's non-generic</p>



<a name="214326318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326318">(Oct 23 2020 at 15:15)</a>:</h4>
<p>Like it get's optimized to</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">alloc</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="n">FOO</span>: <span class="nc">fn</span><span class="p">(</span><span class="kt">usize</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="n">Layout</span><span class="p">,</span><span class="w"> </span><span class="n">LayoutErr</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Layout</span>::<span class="n">array</span>::<span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
</code></pre></div>

<div class="codehilite" data-code-language="LLVM"><pre><span></span><code><span class="nv">%"unwind::libunwind::_Unwind_Exception"</span> <span class="p">=</span> <span class="k">type</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="k">i64</span><span class="p">,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="k">void</span> <span class="p">(</span><span class="k">i32</span><span class="p">,</span> <span class="nv">%"unwind::libunwind::_Unwind_Exception"</span><span class="p">*)*,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="p">[</span><span class="m">6</span> <span class="k">x</span> <span class="k">i64</span><span class="p">],</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i64</span><span class="p">]</span> <span class="p">}</span>
<span class="nv">%"unwind::libunwind::_Unwind_Context"</span> <span class="p">=</span> <span class="k">type</span> <span class="p">{</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]</span> <span class="p">}</span>

<span class="vg">@_ZN7example3FOO17h3e16beda867c4de3E</span> <span class="p">=</span> <span class="k">local_unnamed_addr</span> <span class="k">constant</span> <span class="p">&lt;{</span> <span class="k">i8</span><span class="p">*,</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]</span> <span class="p">}&gt;</span> <span class="p">&lt;{</span> <span class="k">i8</span><span class="p">*</span> <span class="k">bitcast</span> <span class="p">({</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i64</span> <span class="p">}</span> <span class="p">(</span><span class="k">i64</span><span class="p">)*</span> <span class="vg">@_ZN4core5alloc6layout6Layout5array17hdd11ae32dc7e30ecE</span> <span class="k">to</span> <span class="k">i8</span><span class="p">*),</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]</span> <span class="k">zeroinitializer</span> <span class="p">}&gt;,</span> <span class="k">align</span> <span class="m">8</span>

<span class="k">define</span> <span class="k">internal</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i64</span> <span class="p">}</span> <span class="vg">@_ZN4core5alloc6layout6Layout5array17hdd11ae32dc7e30ecE</span><span class="p">(</span><span class="k">i64</span> <span class="nv">%n</span><span class="p">)</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span> <span class="k">personality</span> <span class="k">i32</span> <span class="p">(</span><span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i64</span><span class="p">,</span> <span class="nv">%"unwind::libunwind::_Unwind_Exception"</span><span class="p">*,</span> <span class="nv">%"unwind::libunwind::_Unwind_Context"</span><span class="p">*)*</span> <span class="vg">@rust_eh_personality</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!6</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="nv nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">tail</span> <span class="k">call</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i1</span> <span class="p">}</span> <span class="vg">@llvm.umul.with.overflow.i64</span><span class="p">(</span><span class="k">i64</span> <span class="nv">%n</span><span class="p">,</span> <span class="k">i64</span> <span class="m">8</span><span class="p">)</span> <span class="vg">#3</span><span class="p">,</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!13</span>
  <span class="nv nv-Anonymous">%1</span> <span class="p">=</span> <span class="k">extractvalue</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i1</span> <span class="p">}</span> <span class="nv nv-Anonymous">%0</span><span class="p">,</span> <span class="m">1</span><span class="p">,</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!13</span>
  <span class="nv nv-Anonymous">%2</span> <span class="p">=</span> <span class="k">extractvalue</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i1</span> <span class="p">}</span> <span class="nv nv-Anonymous">%0</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!23</span>
  <span class="nv">%.sroa.3.0</span> <span class="p">=</span> <span class="k">select</span> <span class="k">i1</span> <span class="nv nv-Anonymous">%1</span><span class="p">,</span> <span class="k">i64</span> <span class="m">0</span><span class="p">,</span> <span class="k">i64</span> <span class="m">8</span><span class="p">,</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!23</span>
  <span class="nv nv-Anonymous">%3</span> <span class="p">=</span> <span class="k">insertvalue</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i64</span> <span class="p">}</span> <span class="k">undef</span><span class="p">,</span> <span class="k">i64</span> <span class="nv nv-Anonymous">%2</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!24</span>
  <span class="nv nv-Anonymous">%4</span> <span class="p">=</span> <span class="k">insertvalue</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i64</span> <span class="p">}</span> <span class="nv nv-Anonymous">%3</span><span class="p">,</span> <span class="k">i64</span> <span class="nv">%.sroa.3.0</span><span class="p">,</span> <span class="m">1</span><span class="p">,</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!24</span>
  <span class="k">ret</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i64</span> <span class="p">}</span> <span class="nv nv-Anonymous">%4</span><span class="p">,</span> <span class="nv">!dbg</span> <span class="nv nv-Anonymous">!24</span>
<span class="p">}</span>

<span class="k">declare</span> <span class="p">{</span> <span class="k">i64</span><span class="p">,</span> <span class="k">i1</span> <span class="p">}</span> <span class="vg">@llvm.umul.with.overflow.i64</span><span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i64</span><span class="p">)</span> <span class="vg">#1</span>

<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@rust_eh_personality</span><span class="p">(</span><span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i64</span><span class="p">,</span> <span class="nv">%"unwind::libunwind::_Unwind_Exception"</span><span class="p">*,</span> <span class="nv">%"unwind::libunwind::_Unwind_Context"</span><span class="p">*)</span> <span class="k">unnamed_addr</span> <span class="vg">#2</span>

<span class="k">attributes</span> <span class="vg">#0</span> <span class="p">=</span> <span class="p">{</span> <span class="k">inlinehint</span> <span class="k">nonlazybind</span> <span class="k">uwtable</span> <span class="s">"probe-stack"</span><span class="p">=</span><span class="s">"__rust_probestack"</span> <span class="s">"target-cpu"</span><span class="p">=</span><span class="s">"x86-64"</span> <span class="p">}</span>
<span class="k">attributes</span> <span class="vg">#1</span> <span class="p">=</span> <span class="p">{</span> <span class="k">nounwind</span> <span class="k">readnone</span> <span class="k">speculatable</span> <span class="k">willreturn</span> <span class="p">}</span>
<span class="k">attributes</span> <span class="vg">#2</span> <span class="p">=</span> <span class="p">{</span> <span class="k">nounwind</span> <span class="k">nonlazybind</span> <span class="k">uwtable</span> <span class="s">"probe-stack"</span><span class="p">=</span><span class="s">"__rust_probestack"</span> <span class="s">"target-cpu"</span><span class="p">=</span><span class="s">"x86-64"</span> <span class="p">}</span>
<span class="k">attributes</span> <span class="vg">#3</span> <span class="p">=</span> <span class="p">{</span> <span class="k">nounwind</span> <span class="p">}</span>
</code></pre></div>



<a name="214326332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326332">(Oct 23 2020 at 15:15)</a>:</h4>
<p>so we probably want to inline that</p>



<a name="214326474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326474">(Oct 23 2020 at 15:16)</a>:</h4>
<p>I wouldn't worry too much about it -- realistically AFAIK LLVM struggles much more with big functions</p>



<a name="214326485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326485">(Oct 23 2020 at 15:16)</a>:</h4>
<p>and this looks like it is on average ~118 lines long</p>



<a name="214326566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326566">(Oct 23 2020 at 15:17)</a>:</h4>
<p>get query impl, for example, is 1105 lines long on average</p>



<a name="214326594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Layout%3A%3Aarray/near/214326594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Layout.3A.3Aarray.html#214326594">(Oct 23 2020 at 15:17)</a>:</h4>
<p>which is likely to be much much worse for compile times</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>